package com.itheima.user.controller;

import com.itheima.user.domain.po.User;
import com.itheima.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ZhuanZ（无密码）
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户管理")
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping("/login")
    @ApiOperation(value = "用户登录", notes = "根据手机号和密码进行用户登录")
    public String login(@RequestParam String phone, @RequestParam String pwd) {
        return userService.login(phone, pwd);
    }

    @PostMapping
    @ApiOperation(value = "用户注册", notes = "注册新用户")
    public void register(@RequestBody User user) {
        userService.register(user);
    }

    @PutMapping
    @ApiOperation(value = "更新用户信息", notes = "更新现有用户的信息")
    public void update(@RequestBody User user) {
        userService.updateUser(user);
    }

    @DeleteMapping
    @ApiOperation(value = "删除用户", notes = "根据用户ID删除用户")
    public void delete(@RequestParam Long id) {
        userService.deleteUser(id);
    }

    @GetMapping
    @ApiOperation(value = "查询用户", notes = "根据用户ID查询用户")
    public User getUser(@RequestParam Long id) {
        return userService.getUser(id);
    }
}
